package com.snake.test.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.snake.mylibrary.net.OkHttpManager;
import com.snake.mylibrary.utils.ThreadManagerUtil;
import com.snake.test.R;

import okhttp3.FormBody;
import okhttp3.RequestBody;

public class OkHttpActivity extends AppCompatActivity {
    String baseUrl = "http://192.168.1.102:8080/httpweb/";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ok_http);
    }

    public void get(View view){
        ThreadManagerUtil.getInstance().getFixedThreadPool().execute(new Runnable() {
            @Override
            public void run() {
                String url = baseUrl+"login?username=get&password=123";
                OkHttpManager.getInstance().httpGet(url);
            }
        });

    }
    public void post(View view){
        ThreadManagerUtil.getInstance().getFixedThreadPool().execute(new Runnable() {
            @Override
            public void run() {
                String url = baseUrl+"login";
                RequestBody requestBody = new FormBody.Builder()
                        .add("username","post")
                        .add("password","1234")
                        .build();
                OkHttpManager.getInstance().httpPost(url, requestBody);
            }
        });

    }

    public void postString(View view){
        ThreadManagerUtil.getInstance().getFixedThreadPool().execute(new Runnable() {
            @Override
            public void run() {
                String url = baseUrl+"postString";
                String param = "{username:snake,password:snake}";
                OkHttpManager.getInstance().httpPostString(url, param);
            }
        });

    }
}
